import java.util.Arrays;

/**
 * @ClassName LC1089
 * @Author ykx
 * @Date 2024/7/7 13:55
 * @Version 1.0
 */
public class LC1089 {

    public static void main(String[] args) {
        LC1089 lc1089 = new LC1089();
        int[] ints = {1, 0, 2, 3, 0, 4, 5, 0};
        System.out.println(Arrays.toString(ints));
        lc1089.duplicateZeros(ints);
        System.out.println(Arrays.toString(ints));
    }

    public void duplicateZeros(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == 0) {
                right(arr, i);
                i++;
            }
        }
    }

    public void right(int[] arr, int from) {
        for (int i = arr.length - 2; i >= from; i--) {
            arr[i + 1] = arr[i];
        }
    }

}
